package service

import (
	"singo/model"
	"singo/serializer"
	// "github.com/segmentio/ksuid"
	// "github.com/rs/xid"
)

// UserDeleteService 管理用户删除服务
type UserDeleteService struct {
}

// Delete 用户删除
func (service *UserDeleteService) Delete(id string) serializer.Response {
	user := model.User{}

	err := model.DB.Where("uid = ?", id).First(&user).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "用户不存在",
			Error:  err.Error(),
		}
	}

	if err := model.DB.Model(&user).Where("uid = ?", id).Delete(&user).Error; err != nil {
		return serializer.ParamErr("删除失败", err)
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
